<template>
  <div>
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
      style="text-align: left"
    >
      <el-form-item>
        <el-form-item label="巡更计划名称">
          <el-input
            v-model="formInline.patrolplanName"
            placeholder="巡更计划名称"
          ></el-input>
        </el-form-item>
        <el-button
          style="background-color: green; color: white"
          icon="el-icon-search"
          @click="list"
          >查询</el-button
        >
        <el-button style="color: gray" icon="el-icon-refresh">重置</el-button>
      </el-form-item>
    </el-form>
    <template>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="id" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="patrolplanName" label="计划名称" align="center">
        </el-table-column>
        <el-table-column prop="patrolPlanDate" label="巡更日期" align="center">
        </el-table-column>
        <el-table-column prop="patrolDate" label="巡更时间段" align="center">
        </el-table-column>
        <el-table-column prop="answersum" label="应巡更总数" align="center">
        </el-table-column>
        <el-table-column prop="alreadysum" label="已巡更总数" align="center">
        </el-table-column>
        <el-table-column prop="notsum" label="未巡更总数" align="center">
          <template slot-scope="scope">
            <span style="color: red">
              {{ scope.row.notsum }}
            </span>
          </template>
        </el-table-column>
        <el-table-column prop="accomplish" label="巡更完成率" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              style="color: green"
              @click="check(scope.row.patrolSiteId)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="countnum"
    >
    </el-pagination>

    <el-dialog title="巡更计划详情" :visible.sync="dialogFormVisible">
      计划名称：<span style="color: green">晚班巡更计划</span><t /><t />
      巡更日期：<span style="color: green">2021-08-02</span><t /><t />
      应巡更数：<span style="color: green">10</span><t /><t /> 已巡更数：<span
        style="color: green"
        >8</span
      ><t /><t /> 未巡更数：<span style="color: green">2</span><t /><t />
      超时巡更数：<span style="color: green">0</span><t /><t />
      巡更完成率：<span style="color: green">80%</span><t /><t />
      <template>
        <el-table :data="tableData1" border style="width: 100%">
          <el-table-column prop="id" label="序号" align="center">
          </el-table-column>
          <el-table-column
            prop="patrolSiteId"
            label="巡更点名称"
            align="center"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.patrolSiteId == 1">1楼消防梯</span>
              <span v-if="scope.row.patrolSiteId == 2">2楼消防梯</span>
            </template>
          </el-table-column>
          <el-table-column prop="userId" label="巡更人员" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.userId == 1">张三</span>
              <span v-if="scope.row.userId == 2">李四</span>
              <span v-if="scope.row.userId == 3">王五</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="patrolDate"
            label="计划巡更时间段"
            align="center"
          >
          </el-table-column>
          <el-table-column prop="time" label="巡更时间" align="center">
          </el-table-column>
          <el-table-column prop="photograph" label="巡更照片" align="center">
            <el-image :src="src" style="width: 30px; height: 30px"></el-image>
          </el-table-column>
          <el-table-column prop="status" label="巡更状态" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.status == true" style="color: green"
                >正常巡更</span
              >
              <span v-if="scope.row.status == false" style="color: red"
                >请假</span
              >
            </template>
          </el-table-column>
          <el-table-column prop="remark" label="巡更备注" align="center">
          </el-table-column>
        </el-table>
      </template>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="formInline1.pageIndex"
        :page-sizes="[1, 2, 3, 4]"
        :page-size="formInline1.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="countnum"
      >
      </el-pagination>
    </el-dialog>
  </div>
</template>
<script>
import {
  GetShowPatrolRecord,
  GetTotaocount,
} from "@/api/SafeManage/PatrolRecord";
import { GetShowPatrolplan, GetPlancount } from "@/api/SafeManage/Patrolplan";
export default {
  data() {
    return {
      src: "https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
      tableData: [],
      dialogFormVisible: false,
      multipleSelection: [],
      ids: {},
      formInline: {
        pageIndex: 1,
        pageSize: 2,
        patrolplanName: "",
      },
      countnum: 0,
      count: 0,

      formInline1: {
        pageIndex: 1,
        pageSize: 2,
      },
      countnum: 0,
      count: 0,
    };
  },
  created() {
    this.list();
    this.listplan();
    this.totalcount();
  },
  methods: {
    //显示
    list() {
      GetShowPatrolRecord(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      this.formInline.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.formInline.pageIndex = val;
      this.list();
    },
    totalcount() {
      GetTotaocount().then((res) => {
        this.countnum = res.data;
      });
    },

    //显示
    listplan() {
      GetShowPatrolplan(this.formInline1).then((res) => {
        this.tableData1 = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      this.formInline1.pageSize = val;
      this.listplan();
    },
    handleCurrentChange(val) {
      this.formInline1.pageIndex = val;
      this.listplan();
    },
    totalcount() {
      GetPlancount().then((res) => {
        this.countnum = res.data;
      });
    },
    //全选/反选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //查看详情
    check() {
      if (this.multipleSelection.length != 1) {
        this.$message.error("请选择一条数据");
        return;
      }
      this.dialogFormVisible = true;
    },
  },
};
</script>
<style>
</style>